<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="js/ajax.js"></script>
</head>
<body>
<div>
    <h1>The Ajax 04 page</h1>
    <fieldset>
        <legend>表单请求</legend>
        <form enctype="application/x-www-form-urlencoded">
            <input type="text" name="name" id="nameId" onblur="doCheck()">
            <button onclick="save()" type="button"> 提交</button>
        </form>
        <span id="result"></span>
    </fieldset>
</div>

</body>
<script>

    function doCheck() {
        let name=document.getElementById("nameId").value;
        ajax.get("/doCheck",`name=${name}`,function (result) {
            debugger;
            document.getElementById("result").innerHTML= "<font color='red'>" +result+ "</font>";
        });
    }

    function save() {
        let name=document.getElementById("nameId").value;
        ajax.post("/doSave",`name=${name}`,function (result) {
            document.getElementById("result").innerText=result;
        })
    }
</script>
</html>